//
//  InvestmentCell.m
//  DaoZiJinFu
//
//  Created by woker on 16/6/27.
//  Copyright © 2016年 iwoker. All rights reserved.
//

#import "InvestmentCell.h"

@implementation InvestmentCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    InvestmentCell *cell = [tableView dequeueReusableCellWithIdentifier:INVEST_CELL];
    if (!cell) {
        cell = [[InvestmentCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:INVEST_CELL];
    }
    return cell;
}

- (void)setUpCell:(InvestListModel *)model {
    _investModel = model;
    _financeLab.text = model.product_name;
    _investMoney.text = [NSString stringWithFormat:@"%.0lf元",[model.total_amount doubleValue]];
    
    _investTime.text = [NSString stringWithFormat:@"%@ 投资",model.pay_time];
    
    if ([model.interest_end_date isKindOfClass:[NSNull class]] == NO) {
        _deadlineLab.text = [NSString stringWithFormat:@"%@ 到期",model.interest_end_date];
    } else {
        _deadlineLab.text = @"";
    }
    
    NSString *incomeStr = [NSString string];
    NSMutableAttributedString *attrStr;
    switch (_segementValue) {
        case 0:{
            float money = [DZNsstringUtil floatInto:[model.gains_amount doubleValue]];
            incomeStr = [NSString stringWithFormat:@"%.2lf",money];
            attrStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"预计收益%@元",incomeStr]];
        }break;
        default:{
            float money = [DZNsstringUtil floatInto:[model.actual_gains_amount doubleValue]];
            incomeStr = [NSString stringWithFormat:@"%.2lf",money];
            attrStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"获得收益%@元",incomeStr]];
        } break;
    }
    
    NSDictionary *preStr = @{NSFontAttributeName:[UIFont systemFontOfSize:14.0f],NSForegroundColorAttributeName:[UIColor lightGrayColor]};
    NSDictionary *amountAttr = @{NSFontAttributeName:[UIFont systemFontOfSize:14.0f],NSForegroundColorAttributeName:ORANGECOLOR};
    NSDictionary *yuanAttr = @{NSFontAttributeName:[UIFont systemFontOfSize:14.0f],NSForegroundColorAttributeName:[UIColor lightGrayColor]};
    [attrStr setAttributes:preStr range:NSMakeRange(0, 4)];
    [attrStr setAttributes:amountAttr range:NSMakeRange(4, incomeStr.length)];
    [attrStr setAttributes:yuanAttr range:NSMakeRange(4+incomeStr.length, 1)];
    _incomeLab.attributedText = [[NSAttributedString alloc] initWithAttributedString:attrStr];
    
    
}

@end
